<template>
  <div>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
      :modal-append-to-body="false"
    >
      <div style="height: 500px">
        <el-row>
          <el-col :span="12">项目名称：{{ projectName }}</el-col>
          <el-col :span="12">项目ID：{{ projectId }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">项目工点名称：{{ pointName }}</el-col>
          <el-col :span="12">项目工点ID：{{ pointId }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="24">考勤机SN编号：{{ machineNO }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">项目总人数：{{ allEmpCount }}</el-col>
          <el-col :span="12">工点在职人数：{{ pointEmpCount }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">成功拉取人数：{{ downEmpCount }}</el-col>
          <el-col :span="12">成功拉取人脸数：{{ downFaceCount }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">成功拉取指纹数：{{ downFPCount }}</el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <el-row style="margin-top: 40px">
          <el-col :span="8" class="cmd-col">
            <el-button
              type="primary"
              icon="el-icon-user"
              class="commonBtn cmd-btn"
              @click="onRestDownEmp()"
              >重新拉取人员</el-button
            >
            <div class="cmd-margin">
              <i class="el-icon-refresh cmd-i"></i>运行中
            </div>
            <div class="cmd-margin">遇到故障时，重新拉取人员考勤机人员数据</div>
          </el-col>
          <el-col :span="8" class="cmd-col">
            <el-button
              type="primary"
              icon="el-icon-switch-button"
              class="commonBtn cmd-btn"
              @click="onReboot()"
              >重启考勤机</el-button
            >
            <div class="cmd-margin">
              <i class="el-icon-refresh cmd-i"></i>运行中
            </div>
            <div class="cmd-margin">遇到故障时,远程重启考勤机</div>
          </el-col>
          <el-col :span="8" class="cmd-col">
            <el-button
              type="primary"
              icon="el-icon-delete"
              class="commonBtn cmd-btn"
              @click="onClearEmp()"
              >清空远程考勤机人员数据</el-button
            >
            <div class="cmd-margin">
              <i class="el-icon-refresh cmd-i"></i>运行中
            </div>
            <div class="cmd-margin">
              遇到故障或项目变更时，远程清空考勤机人员数据
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" class="cmd-col">
            <el-button
              type="primary"
              icon="el-icon-user"
              class="commonBtn cmd-btn"
              @click="onRefreshEmp()"
              >刷新数据</el-button
            >
            <div class="cmd-margin">
              <i class="el-icon-refresh cmd-i"></i>运行中
            </div>
            <div class="cmd-margin">刷新拉取数据</div>
          </el-col>
          <el-col :span="8" class="cmd-col"> </el-col>
          <el-col :span="8" class="cmd-col"> </el-col>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'zktecoMachine',
  data() {
    return {
      dialogVisible: false,
      dialogTitle: '',
      projectId: '',
      pointId: '',
      machineNO: '',
      projectName: '',
      pointName: '',
      allEmpCount: '',
      pointEmpCount: '',
      downEmpCount: '',
      downFPCount: '',
      downFaceCount: '',
    }
  },
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false
    },
    showZktecoDetail(projectId, pointId, machineNo, projectName, pointName) {
      this.dialogTitle = '中控考勤机命令'
      this.projectId = projectId
      this.pointId = pointId
      this.machineNO = machineNo
      this.projectName = projectName
      this.pointName = pointName
      this.onRefreshEmp()
      this.dialogVisible = true
    },
    getWorkPointLatLng(projectId, pointId) {
      this.axios({
        method: 'post',
        url: 'api-att/getWorkPointLatLng',
        data: {
          projectId: projectId,
          projectPoint: pointId,
        },
      })
        .then((res) => {
          this.pointName = res.data.result.pointName
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取数据失败',
            type: 'error',
          })
        })
    },
    onRestDownEmp() {
      this.axios({
        method: 'post',
        url: 'api-att/zkResetEmpMark',
        data: {
          sn: this.machineNO,
          projectId: this.projectId,
          pointId: this.pointId,
        },
      })
        .then((res) => {
          this.$message({
            message: '请求成功',
            type: 'success',
          })
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },
    onReboot() {
      this.axios({
        method: 'post',
        url: 'api-att/restartZKTeco',
        data: {
          sn: this.machineNO,
        },
      })
        .then((res) => {
          this.$message({
            message: '请求成功',
            type: 'success',
          })
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },
    onClearEmp() {
      this.axios({
        method: 'post',
        url: 'api-att/delZKTecoUserInfo',
        data: {
          sn: this.machineNO,
          projectId: this.projectId,
          pointId: this.pointId,
        },
      })
        .then((res) => {
          this.$message({
            message: '请求成功',
            type: 'success',
          })
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },
    onRefreshEmp() {
      this.axios({
        method: 'post',
        url: 'api-att/getEmployeeCount',
        data: {
          machineNo: this.machineNO,
          projectId: this.projectId,
          pointId: this.pointId,
        },
      })
        .then((res) => {
          this.allEmpCount = res.data.empCount
          this.pointEmpCount = res.data.empPointCount
          this.downEmpCount = res.data.empDownCount
          this.downFPCount = res.data.empFPCount
          this.downFaceCount = res.data.empFaceCount
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },
  },
}
</script>

<style scoped lang="less">
.el-col {
  border-radius: 0px;
  border: 1px #dddddd solid;
  height: 36px;
  line-height: 36px;
  background-color: #edeff1;
  padding-left: 10px;
}

.cmd-col {
  border: none;
  height: 180px;
  line-height: 20px;
  background-color: #ebebeb;
  text-align: center;
  padding: 10px;
}
.cmd-btn {
  width: 220px;
  height: 60px;
}
.cmd-i {
  font-size: 32px;
  vertical-align: middle;
  margin-right: 10px;
  color: #389531;
}
.cmd-margin {
  margin-top: 10px;
}
</style>
